<template>

  <div style="width: 100%;height: 100vh;" class="view-box f-column-Wcenter">

    <div class="form-box ">
      <h3 style="border-bottom: #ccc 2px solid;padding-bottom: 30px;">资产发行计算</h3>
      <div class="form ">
        <el-form ref="ruleForm1" :rules="rules1" :hide-required-asterisk="true" @submit.native.prevent
          @keyup.enter.native="stepsBtn(9)" label-position="top" :model="ruleForm1">
          <div class="f-row-between" style="width: 85%;"><span>项目方公司名称：{{details.company}}</span>
            <span>对标商品名称：{{details2.assetName}}</span>
            <span>抵押资产名称：{{details2.mortgage}}</span>
          </div>
          <div class="f-row-between" style="width: 600px;margin-top: 20px;"><span>超发率计算</span></div>
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;">

            <el-form-item prop="exceed_rate" style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>𝛍 </span> </div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.exceed_rate" maxlength="30" placeholder=""></el-input>
              </div>
            </el-form-item>

            <el-form-item style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span> &nbsp;=</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.discount_rate" maxlength="30" placeholder="𝛂(折扣率)"></el-input>
              </div>
            </el-form-item>
            <el-form-item style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span> +</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.cost_factor" maxlength="30" placeholder="𝛃(成本系数)"></el-input>
              </div>
            </el-form-item>
            <el-form-item style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span> +</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.return_factor " maxlength="30" placeholder="𝛉(回报系数)"></el-input>
              </div>
            </el-form-item>
            <el-form-item style="margin-left: 20px;">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span> +</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.loss_factor " maxlength="30" placeholder=" 𝛆(耗系数)"></el-input>
              </div>
            </el-form-item>
            <el-button type="primary" plain style="margin-left: 30px;margin-top: -20px;" @click="onAmountPriceU">执行运算</el-button>
          </div>
          <span style="color: #CCCCCC;">系数参考值： 𝛂=0.25， 𝛃=0.10， 𝛉=0.10， 𝛆=0.05 具体参数值需确认而定。</span>

          <div class="f-row-between" style="width: 600px;margin-top: 50px;"><span>发行总量计算</span></div>
          <div class="f-row-Hcenter " style="width: 100%;">
            <el-form-item prop="stAmount" style=" margin-left: 20px; margin-top:20px; ">
              <div class="f-row-Hcenter">
                <div class="f-row-Hcenter"><span>𝚳</span></div>
                <el-input style="margin-left: 20px;" v-model="ruleForm1.stAmount" maxlength="30" placeholder=""></el-input>
              </div>
            </el-form-item>

            <div class="f-row-Hcenter">
              <div class="f-row-Hcenter"><span> &nbsp;&nbsp;=</span></div>
              <el-input style="margin-left: 20px;" v-model="ruleForm1.compare_project_fund" maxlength="30" placeholder="Z(对标项目总资金)"></el-input>
            </div>
            <div class="f-row-Hcenter">
              <div class="f-row-Hcenter"><span>&nbsp;&nbsp;x</span><span>&nbsp;( </span> <span> &nbsp;&nbsp;1 </span><span> &nbsp;+ </span>
                <el-input disabled style="margin-left: 20px;" v-model="ruleForm1.exceed_rate" maxlength="30" placeholder="𝛍(超发率)"></el-input>
                <span>&nbsp;&nbsp;)</span>
              </div>
            </div>
            <div class="f-row-Hcenter">
              <div class="f-row-Hcenter"><span>&nbsp;&nbsp;÷</span></div>
              <el-input style="margin-left: 20px;" v-model="ruleForm1.start_price" maxlength="30" placeholder="P(首发价)"></el-input>
            </div>
            <el-button type="primary" plain style="margin-left: 30px;" @click="onAmountPriceM">执行运算</el-button>
          </div>
          <span style="color: #CCCCCC;">数值以已计算出的数值输入。</span>
          <div class="f-row-Hcenter " style="width: 100%;margin-top: 20px;">
            <span>流通总量：</span>
            <el-form-item prop="cirAmount" style="margin-top: 20px;">
              <el-input style="margin-left: 20px;width: 100%;" v-model="ruleForm1.cirAmount" maxlength="30" placeholder="输入资产流通总量"></el-input>
            </el-form-item>
          </div>
          <el-form-item prop="ruleFileUrl" style="width: 100%;">
            <div class="f-row-between" style="width: 600px;margin-top: 20px;margin-bottom: 20px;"><span>上传发行规则</span></div>
            <el-upload class="upload-demo upload-li-w50" :action="url+'/platform/attachmentFile/add'" :data="{ userId: userId,type:'ISTO_appraisal_report' }"
              :on-remove="deleteFile_lv_shi" :on-success="uploadFile_lv_shi" multiple :limit="5">
              <el-button size="small" type="primary">选择文件</el-button>
              <div slot="tip" class="el-upload__tip">
                请上传jpg / jpeg / png / pdf文件，文件大小不超过10MB
              </div>
            </el-upload>
          </el-form-item>
        </el-form>

        <div>
          <el-button type="success" plain @click="stepsBtn(9)">终止发行</el-button>
          <el-button type="success" plain @click="stepsBtn(8)">发布</el-button>
        </div>

      </div>
    </div>
  </div>
</template>

<script>
  import serveApi from '@/api/serveApi.js'
  export default {
    name: "Authorization",
    data() {

      return {
        userInfo: '',
        userId: '',
        url: '',
        routeData: {},
        details: {},
        details2: {},
        query1: {
          id: 0,
          applyIstoId: 0
        },

        ruleForm1: {
          id: 0,
          exceed_rate: '', //超发率
          discount_rate: '', //*number(query) 折扣率
          cost_factor: '', //*number(query) 成本系数
          return_factor: '', // *number(query) 回报系数
          loss_factor: '', // *number(query) 损耗系数


          //exceed_rate: '', // *number(query) 超发率
          start_price: '', // *number(query) 首发价
          compare_project_fund: '', // *number(query) 对标项目总资金
          ruleFileUrl: '', //发行规则

          stAmount: '', //  发行总量
          cirAmount: '' //	number  总流通量
        },
        rules1: {
          exceed_rate: [{
            required: true,
            message: "请运算超发率",
            trigger: "blur"
          }],
          stAmount: [{
            required: true,
            message: "请运算发行总量",
            trigger: "blur"
          }],
          cirAmount: [{
            required: true,
            message: "请输入总流通量",
            trigger: "blur"
          }],
          ruleFileUrl: [{
            required: true,
            message: "请上传发行规则"
          }]
        }
      }
    },
    mounted() {
      let that = this;

      that.url = process.env.VUE_APP_BASE_API;
      this.userId = this.$store.state.userInfo.id;
      this.routeData = this.$route.query
      this.getDetails();
      this.getDetails2();
    },
    methods: {
      getDetails() {
        this.query1.id = this.routeData.id;
        serveApi.applySto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details = res.data;
            }
          } else {
            this.$message.error(res.message);
          }
        });
      },
      getDetails2() {
        this.query1.applyIstoId = this.routeData.applyIstoId;
        serveApi.applyIsto_id(this.query1).then(res => {
          if (res.status == "0000") {
            if (res.data) {
              this.details2 = res.data;
            }
          } else {
            that.$message.error(res.message);
          }
        });
      },
      stepsBtn(e) {
        this.ruleForm1.id = this.routeData.applyIstoId;
        if (e == 9) {
          this.ruleForm1.status = e;
          serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
            if (res.data) {
              this.$message.success('驳回成功');
            } else {
              this.$message.error(res.message);
            }
          });
        } else {
          this.ruleForm1.status = e;
           this.ruleForm1.ruleFileUrl = JSON.stringify(this.ruleForm1.ruleFileUrlArr);
          this.$refs.ruleForm1.validate(valid => {
            if (valid) {
              serveApi.applyIsto_applyIsto(this.ruleForm1).then(res => {
                if (res.data) {
                  this.$message.success('发布成功');
                } else {
                  this.$message.error(res.message);
                }
              });
            }
          })
        }
      },

      deleteFile_lv_shi(response, file, fileList) {
        let index = this.ruleForm1.ruleFileUrlArr.findIndex(function(student) {
          return student.name == response.name;
        })
        this.ruleForm1.ruleFileUrlArr.splice(index, 1);
      },
      uploadFile_lv_shi(response, file, fileList) {
        this.ruleForm1.ruleFileUrlArr = this.ruleForm1.ruleFileUrlArr || [];
        response.data.name = file.name;
        this.ruleForm1.ruleFileUrlArr.push(response.data);
        this.$upload("ruleForm1", "ruleFileUrl");
      },
      onAmountPriceU() {
        if (this.ruleForm1.discount_rate <= 0) {
          this.$message.error('请输入𝛂(折扣率)');
          return
        }
        if (this.ruleForm1.cost_factor <= 0) {
          this.$message.error('请输入𝛃(成本系数)');
          return
        }
        if (this.ruleForm1.return_factor <= 0) {
          this.$message.error('请输入𝛉(回报系数)');
          return
        }
        if (this.ruleForm1.loss_factor <= 0) {
          this.$message.error('请输入𝛆(耗系数)');
          return
        }
        serveApi.exceed_rate(this.ruleForm1).then(res => {
          if (res.data) {
            this.ruleForm1.exceed_rate = res.data.exceed_rate;
            this.$message.success('运算成功');
          } else {
            this.$message.error(res.message);
          }
        });
      },
      onAmountPriceM() {

        if (this.ruleForm1.exceed_rate <= 0) {
          this.$message.error('请运算𝛍(超发率)');
          return
        }
        if (this.ruleForm1.compare_project_fund <= 0) {
          this.$message.error('请输入Z(对标项目总资金)');
          return
        }
        if (this.ruleForm1.start_price <= 0) {
          this.$message.error('请输入P(首发价)');
          return
        }
        serveApi.system_issue(this.ruleForm1).then(res => {
          if (res.data) {
            this.ruleForm1.stAmount = res.data.issue_total_amount;
            this.$message.success('运算成功');
          } else {
            this.$message.error(res.message);
          }
        });
      }
    }
  }
</script>
<style>
  .upload-demo .el-upload {
    width: 100%;
  }
</style>
<style scoped lang="scss">
  /* 表单的lable */
  .el-form--label-top .el-form-item__label {
    float: none;
    display: inline-block;
    text-align: left;
    padding: 0;


    font-size: 14px;
    font-family: MicrosoftYaHei;
    color: #3B3734;
  }
</style>
<style scoped lang="scss">
  .view-box {
    background-color: #ece9e7;
  }

  h6 {
    height: 73px;
    font-size: 36px;
    font-family: MicrosoftYaHeiSemibold;
    color: #3B3734;
    line-height: 48px;
    letter-spacing: 1px;
    position: relative;

    &::after {
      content: '';
      width: 66px;
      position: absolute;
      border-bottom: 2px solid #007AFF;
      bottom: 0px;
      margin-top: 25px;
    }
  }

  .form-box {
    width: 95%;
    // height: 800px;
    background: #FFFFFF;
    box-shadow: 0px 0px 10px 0px rgba(178, 178, 178, 0.2);
    border-radius: 4px;
    margin-top: 47px;
    padding: 24px;
    margin-bottom: 50px;


  }

  .upload-demo {
    width: 50%;

    button {
      width: 50%;
    }

    .el-upload {

      width: 100%;

      .el-button {
        height: 50px;
        width: 100%;
        background: transparent;
        color: rgba(43, 139, 195, 1);
        font-size: 14px;
        border: 1px dashed #dddddd;
      }
    }

    .el-upload__tip {
      line-height: 20px;
      color: rgba(153, 153, 153, 1);
      font-size: 13px;

      a {
        color: rgba(43, 139, 195, 1);
        cursor: pointer;
      }
    }
  }
</style>
